<?php

namespace app\common\model\stall;

use app\common\model\BaseModel;

class Category extends BaseModel
{
    protected $name = 'stall_category';
    protected $pk = 'id';

    public static function checkDB($stallid, $categoryid, $checktype = false)
    {
        $where = [];
        if (!$checktype) {
            $where = ['is_delete' => 0];
        }
        return self::where(['stall_id' => $stallid, 'category_id ' => $categoryid])->where($where)->find();
    }

    public static function updateShowStatus($id, $status, $savedata)
    {
        $model = self::detail($id);
        if ($model) {
            return $model->save($status == 1 ? ['is_delete' => 1] : ['is_delete' => 0]);
        } else {
            if ($status == 0) {
                return (new self)->save($savedata);
            }
            return true;
        }
    }

    public static function detail($id)
    {
        return (new static())->where('id', '=', $id)->find();
    }
}